//
//  YLSignSuccessViewController.m
//  TheTenthAnniversaryOfMobileUnion
//
//  Created by kuangbiao on 2019/1/24.
//  Copyright © 2019 kuangbiao. All rights reserved.
//

#import "YLSignSuccessViewController.h"
#import "YLSignFailedViewController.h"
#import "YLSearchUserModel.h"
#import "YLAlertView.h"

@interface YLSignSuccessViewController ()
//用户头像
@property (weak, nonatomic) IBOutlet UIImageView *userHeadImageView;
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;
@property (weak, nonatomic) IBOutlet UIButton *enterBtn;
@property (weak, nonatomic) IBOutlet UILabel *realNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *partmentLabel;
@property (weak, nonatomic) IBOutlet UILabel *seatLabel;
@property (nonatomic, strong) YLAlertView *alertView;

@end

@implementation YLSignSuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
}

- (void)initView{
    self.cancelBtn.layer.cornerRadius = 30;
    self.enterBtn.layer.cornerRadius = 30;
    self.userHeadImageView.layer.cornerRadius = 213.5f;
    [self.userHeadImageView yy_setImageWithURL:[NSURL URLWithString:self.userModel.headImg?:@""] placeholder:[UIImage imageNamed:@"panda img"]];
    self.realNameLabel.text = self.userModel.realName?:@"";
    self.partmentLabel.text = self.userModel.belongGroup?:@"";
    self.seatLabel.text = self.userModel.seatInfo?:@"";
}

#pragma mark - 取消按钮点击事件
- (IBAction)cancelBtnClickAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 确认签到
extern NSString *kServerHttpBaseUrl;
- (IBAction)enterBtnClickAction:(id)sender {
    NSString *url = [NSString stringWithFormat:@"%@%@",kServerHttpBaseUrl,kUserSign_url];
    NSDictionary *params = @{@"userNo":self.userModel.userNo?:@"",@"meetNo":[CMBasicData getMerInfo].meetingNo?:@"",@"signType":@"sceneHand"};
    [HttpRequest requestWithURLString:url parameters:params type:HttpRequestTypePost success:^(id responseObject) {
        NSDictionary *dict = responseObject;
        YLHttpModel *httpModel = [YLHttpModel yy_modelWithDictionary:dict];
        if([httpModel.status isEqualToString:@"200"]){
            
            self.alertView = [[YLAlertView alloc] initWithFrame:self.navigationController.view.frame];
            self.alertView.nameLabel.text = [NSString stringWithFormat:@"%@ 签到成功",self.userModel.realName?:@""];
            self.alertView.companyLabel.text = self.userModel.belongGroup?:@"";
            self.alertView.tableLabel.text = self.userModel.seatInfo?:@"";
            [self.navigationController.view addSubview:self.alertView];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.alertView removeFromSuperview];
                [self.navigationController popViewControllerAnimated:YES];
            });
            
        }else{
            [KDAlertView alertWithMessage:httpModel.msg?:@""];
        }
    } failure:^(NSError *error) {
        [KDLoadFrame withState:KDLoadStateError];
    }];
}

@end
